

@file:JvmName("TestShowUi")

package com.example.mylitepaldemo.composeui

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.modifier.modifierLocalConsumer
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.mylitepaldemo.MainActivity.numb
import com.example.mylitepaldemo.composeui.components.home.EumnData
import com.example.mylitepaldemo.composeui.components.home.Home_EumnList
import com.example.mylitepaldemo.composeui.components.home.Home_EumnList2
import com.example.mylitepaldemo.composeui.components.utils.getApplication
import com.example.mylitepaldemo.composeui.components.utils.showToast
import com.example.mylitepaldemo.composeui.navig.SwitchRegion

fun setContent(composeView: ComposeView) {
    composeView.setContent {

        SwitchRegion()//页面跳转
//        contentView ()//测试页
//        listViewTest() // listview
    }
}
@Preview
@Composable
fun listViewTest() {
    var showOne by remember {
        mutableStateOf(true)
    }
    Column {

        Row(
            Modifier
                .fillMaxWidth()
                .height(50.dp),  verticalAlignment = Alignment.CenterVertically) {
            Text("Tap1",Modifier.weight(1f).background(Color.Blue).fillMaxHeight().align(Alignment.CenterVertically)
                .clickable { showOne = true}
                ,textAlign = TextAlign.Center)
            Text("Tap2",Modifier.align(Alignment.CenterVertically).weight(1f).background(Color.Red).height(50.dp)
                .clickable { showOne = false},textAlign = TextAlign.Center)
        }
        LazyColumn {

            items( if(showOne) Home_EumnList else Home_EumnList2 ){
                it.items.forEach {
                   EumnItemView(it)
                }
            }
      }
    }


}

@Composable
fun EumnItemView(eumnData: EumnData) {

    val navController = rememberNavController()
    Box (
        Modifier.clickable {

        }
            .fillMaxWidth()
            .height(100.dp)
            .background(Color.Gray), Alignment.Center){
        Text(text =eumnData.text,color= Color.White )
    }
    Divider(modifier = Modifier
        .height(1.dp)
        .fillMaxWidth()
        .background(Color.White)
    )
}

@Composable
fun contentView() {

    var isPressed by remember {
        mutableStateOf(numb)
    }
    Column(modifier = Modifier
        .background(Color.Red)
        .clickable {
            isPressed = 6000
            val main = com.example.mylitepaldemo.MainActivity()
            main.showToast(getApplication())
        }, verticalArrangement = Arrangement.Center){
        Text(text = "你好 我是compose Text()组件" + isPressed,
            Modifier
                .clickable { isPressed = 4999 }
                .background(Color.Green))
        if(isPressed > 5000){
            Text("已经大于5000了,铁子！",Modifier.background(Color.Blue))
        }
    }
}


